import lombok.extern.slf4j.Slf4j;
import model.Iec104Master;
import model.ModusTable;
import model.SysIpconfig;
import service.ModusTableService;
import service.SysIpconfigService;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Slf4j
public class Start {
	public static void main(String[] args) {
		Map<String, SysIpconfig> smap = SysIpconfigService.getInstance().getSysIpconfigMap();

		List<Iec104Master> list = new ArrayList<>();
		Iec104Master master;
		List<ModusTable> moduses;
		for (Map.Entry<String, SysIpconfig> e : smap.entrySet()) {
			if (e.getValue().getStatus() == 0) {
				moduses = ModusTableService.getInstance().getAllModusTable(e.getValue().getIpId());
				if (moduses != null && moduses.size() > 0) {
					log.warn("为{}创建通道", e.getKey());
					master = new Iec104Master(e.getValue(), moduses);
					list.add(master);
					log.warn("开启通道{}", e.getKey());
					master.start();
					log.warn("开启通道{}完毕", e.getKey());
				}
			} else {
				log.warn("通道{}下无点位", e.getKey());
			}
		}
		for (; ; ) {
			//evenloop  阻断线程
			try {
				Thread.sleep(5000L);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
